using System;
using System.Reflection;

namespace Sunny.UI;

public static class DeepCopy
{
	public static T ReflectionCopy<T>(T obj) where T : class, new()
	{
		Type type = obj.GetType();
		object obj2 = Activator.CreateInstance(type);
		PropertyInfo[] properties = type.GetProperties();
		foreach (PropertyInfo propertyInfo in properties)
		{
			propertyInfo.SetValue(obj2, propertyInfo.GetValue(obj, null), null);
		}
		return (T)obj2;
	}

	public static T ExpressionCopy<T>(T obj) where T : class, new()
	{
		return TransExp<T, T>.Trans(obj);
	}

	public static TOut ExpressionCopy<TIn, TOut>(TIn obj) where TIn : class, new() where TOut : class, new()
	{
		return TransExp<TIn, TOut>.Trans(obj);
	}
}
